jsMath

Sustavi linearnih jednadzbi

""" Ivan Andrić, Ana Jerbic """ 
       
var('a,b,c') 
       
(a, b, c)
rj = [a+b*c==1, b-c*a==0, a+b==5] 
       
s = solve(rj, a,b,c);s # ovako vec znamo rijesiti sustav 
       
[[a == (25*I*sqrt(79) + 25)/(6*I*sqrt(79) - 34), b == (5*I*sqrt(79)
+ 5)/(I*sqrt(79) + 11), c == 1/10*I*sqrt(79) + 1/10], [a ==
(25*I*sqrt(79) - 25)/(6*I*sqrt(79) + 34), b == (5*I*sqrt(79) -
5)/(I*sqrt(79) - 11), c == -1/10*I*sqrt(79) + 1/10]]
print latex(s) # ispisivanje rjesenja u latex kodu, pomocu funkcije latex 
       
\left[\left[a = \frac{25 i \, \sqrt{79} + 25}{6 i \, \sqrt{79} -
34}, b = \frac{5 i \, \sqrt{79} + 5}{i \, \sqrt{79} + 11}, c =
\frac{1}{10} i \, \sqrt{79} + \frac{1}{10}\right], \left[a =
\frac{25 i \, \sqrt{79} - 25}{6 i \, \sqrt{79} + 34}, b = \frac{5 i
\, \sqrt{79} - 5}{i \, \sqrt{79} - 11}, c = -\frac{1}{10} i \,
\sqrt{79} + \frac{1}{10}\right]\right]
view(s) # da bi ovo radilo trebamo imati instaliranu neku LaTeX distribuciju, npr. TeX Live 
       
[[a=6i793425i79+25,b=i79+115i79+5,c=110i79+110],[a=6i79+3425i7925,b=i79115i795,c=110i79+110]] 
A = Matrix([[1,2,3],[3,2,1],[1,2,0]]) # stvaranje matrice 
       
X = vector([0,-4,-1]) # stvaranje vektora 
       
Y = A.solve_right(X); Y 
       
(-5/3, 1/3, 1/3)
A * Y # provjera rjesenja 
       
(0, -4, -1)
A \ X # mozemo koristiti operator \ umjesto A.solve_right(X) 
       
(-5/3, 1/3, 1/3)
A / Y 
       
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for '/': 'Full MatrixSpace
of 3 by 3 dense matrices over Integer Ring' and 'Vector space of
dimension 3 over Rational Field'